a = int(input())
max_ = 0
k1 = 1000
while k1 != 0:
    b = a // k1 % 10
    c = 2
    while b != 1 and c < b and b / c % 1 != 0:
        c += 1
    if c == b and b > max_:
        max_ = int(b)
    k1 //= 10
k1 = 1000
k2 = 100
while k2 != 0:
    b = int(str(a // k1 % 10) + str(a // k2 % 10))
    c = 2
    while b != 1 and c < b and b / c % 1 != 0:
        c += 1
    if c == b and b > max_:
        max_ = int(b)
    k1 //= 10
    k2 //= 10
k1 = 1000
k2 = 100
k3 = 10
while k3 != 0:
    b = int(str(a // k1 % 10) + str(a // k2 % 10) + str(a // k3 % 10))
    c = 2
    while b != 1 and c < b and b / c % 1 != 0:
        c += 1
    if c == b and b > max_:
        max_ = int(b)
    k1 //= 10
    k2 //= 10
    k3 //= 10
k1 = 1000
k2 = 100
k3 = 10
k4 = 1
while k4 != 0:
    b = int(str(a // k1 % 10) + str(a // k2 % 10) + str(a // k3 % 10) + str(a // k4 % 10))
    c = 2
    while b != 1 and c < b and b / c % 1 != 0:
        c += 1
    if c == b and b > max_:
        max_ = int(b)
    k1 //= 10
    k2 //= 10
    k3 //= 10
    k4 //= 10
print(max_)